package com.spit.fammo.api

import android.os.Bundle
import androidx.navigation.NavController
import androidx.navigation.NavOptions
import com.blankj.utilcode.util.ActivityUtils
import com.google.gson.Gson
import com.spit.fammo.MainActivity
import com.spit.fammo.R
import com.spit.fammo.bean.db.AssetBean
import com.spit.fammo.ui.act.LoginAct
import com.spit.fammo.ui.act.ZxingAct
import me.hgj.jetpackmvvm.ext.navigateAction


/**
 * Created by Administrator on 2017/2/22.
 */

class UIHelper private constructor() {

    init {
        throw UnsupportedOperationException("u can't instantiate me...")
    }

    companion object {

        val navOptions = NavOptions.Builder()
            .setEnterAnim(R.anim.slide_in_right)  // 设置进入动画
            .setExitAnim(R.anim.slide_out_left)  // 设置退出动画
            .setPopEnterAnim(R.anim.slide_in_left)  // 设置返回动画
            .setPopExitAnim(R.anim.slide_out_right)  // 设置返回退出动画
            .build()

        fun startMainAct() {
            ActivityUtils.startActivity(MainActivity::class.java)
        }

        /**
         *  登录
         */
        fun startLoginAct() {
            ActivityUtils.startActivity(LoginAct::class.java)
        }

        /**
         *  二维码
         */
        fun startZxingAct(type: Int) {
            val bundle = Bundle()
            bundle.putInt("type", type)
            ActivityUtils.startActivity(bundle, ZxingAct::class.java)
        }


        /**
         *  设置
         */
        fun startSettingFrg(nav: NavController) {
            nav.navigateAction(R.id.action_mainfragment_to_settingFragment, Bundle().apply {
                putString("key", "test")
            })
        }

        /**
         *  资产详情
         */
        fun startAssetsDetailFrg(nav: NavController, id: String?, statusid: Int) {
            nav.navigate(R.id.assetsDetailFrg, Bundle().apply {
                putString("id", id)
                putInt("statusid", statusid)
            }, navOptions)
        }
        fun startAssetsDetailFrg(nav: NavController, bean: AssetBean?, id:String?, type: Int) {
            nav.navigate(R.id.assetsDetailFrg, Bundle().apply {
                putString("id", id)
                putInt("type", type)
                putString("bean", Gson().toJson(bean))
                putInt("statusid", bean!!.statusid)
                putString("stocktakeno", bean!!.stocktakeno)
            }, navOptions)
        }

        /**
         *  盘点订单列表
         */
        fun startStockTakeListFrg(nav: NavController) {
            nav.navigate(R.id.stockTakeListFrg,)
        }

        /**
         *  下载
         */
        fun startDownloadFrg(nav: NavController) {
            nav.navigate(R.id.downloadFrg,)
        }

        /**
         *  上传
         */
        fun startUploadFrg(nav: NavController) {
            nav.navigate(R.id.uploadFrg)
        }

        /**
         *  配置信号
         */
        fun startPowerSettingFrg(nav: NavController) {
            nav.navigate(R.id.powerSettingFrg)
        }

        /**
         *  资产详情
         */
        fun startAssetFrg(nav: NavController, stocktakeno: String?, name: String?) {
            nav.navigate(R.id.action_stockTakeListFrg_to_assetFrg, Bundle().apply {
                putString("orderId", stocktakeno)
                putString("name", name)
            })
        }

    }
}

